<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">

    <f:view contentType="text/html">

        <p:panel widgetVar="topBar" style="height: 150px; text-align: right; background: url('/MacTeam-war/images/bg.png') no-repeat; background-size: 100%; color: white; border: 5px solid white;">
            <h:form>
                <h:outputLink style="color: white" id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login" rendered="#{!loginBacking.userLoggedIn}">     
                    login
                </h:outputLink>
                <h:outputText style="color: white" value=" | " rendered="#{!loginBacking.userLoggedIn}"/>
                <h:commandLink style="color: white" id="RegisterLink" immediate="true"  action="#{salesLeadEntityController.prepareRegister}" rendered="#{!loginBacking.userLoggedIn}">     
                    register 
                </h:commandLink>

                <h:commandLink style="color: white"  immediate="true"  action="/main" rendered="#{loginBacking.userLoggedIn}">     
                    WorkSpace
                </h:commandLink>
                <h:outputText style="color: white" value=" | " rendered="#{loginBacking.userLoggedIn}"/>
                <h:commandLink style="color: white" action="#{contactEntityController.viewAccount}" rendered="#{loginBacking.userLoggedIn}">   
                    <h:outputText style="color: white" value="#{loginBacking.loginPerson.firstName}" />
                    <h:outputText style="color: white" value="'s account"/>
                </h:commandLink> 
                <h:outputText style="color: white" value=" | " rendered="#{loginBacking.userLoggedIn}"/>
                <h:commandLink style="color: white" id="logout" action="#{loginBacking.logout}" rendered="#{loginBacking.userLoggedIn}">     
                    logout 
                </h:commandLink>
            </h:form>
        </p:panel>

        <p:growl id="growl" showDetail="true" life="3000" />  

        <p:dialog id="dialog" header="Login" widgetVar="dlg"> 

            <h:form>  
                <p:focus />
                <h:panelGrid columns="2" cellpadding="5">                      
                    <h:outputLabel for="username" value="Username: *" />  
                    <p:inputText value="#{loginBacking.name}"   
                                 id="username" required="true" label="username" />  

                    <h:outputLabel for="password" value="Password: * " />  
                    <h:inputSecret value="#{loginBacking.password}"   
                                   id="password" required="true" label="password" />  

                    <f:facet name="footer">  
                        <p:commandButton value="Login" update="growl"   
                                         actionListener="#{loginBacking.login}"   
                                         oncomplete="handleLoginRequest(xhr, status, args)"/> 
                        <h:outputLink value="javascript:void(0)" onclick="forgetpassword.show()">
                            Forget Password
                        </h:outputLink>
                    </f:facet> 

                </h:panelGrid>                                

            </h:form>  
        </p:dialog>  

        <p:dialog id="dialog2" header="Forget Password" widgetVar="forgetpassword"> 

            <h:form>  
                <p:focus />
                <h:panelGrid columns="2" cellpadding="5">                      
                    <h:outputLabel for="username" value="Email: *" />  
                    <p:inputText value="#{passwordChangeRequestController.passwordChangeRequestEmail}"   
                                 id="passwordChangeRequestEmail" required="true" />    

                    <f:facet name="footer">  
                        <p:commandButton value="Get it Back!" update="growl"   
                                         actionListener="#{passwordChangeRequestController.forgetPassword}"   
                                         oncomplete="forgetpassword.hide()">                           
                        </p:commandButton>
                        <h:outputLink value="javascript:void(0)"      
                                      onclick="forgetpassword.hide()">
                            Cancel
                        </h:outputLink> 
                        <p:ajaxStatus style="width:16px;height:16px;">  
                            <f:facet name="start">  
                                <h:graphicImage value="/resources/design/ajaxloading.gif" />  
                            </f:facet>  

                            <f:facet name="complete">  
                                <h:outputText value="" />  
                            </f:facet>  
                        </p:ajaxStatus>                       
                    </f:facet> 

                </h:panelGrid>                                

            </h:form>  
        </p:dialog>
  
        <script type="text/javascript">  
            function handleLoginRequest(xhr, status, args) {  
                
                if(args.validationFailed || !args.loggedIn) {  
                    jQuery('#dialog').parent().effect("shake", { times:3 }, 100);  
                } else {  
                    dlg.hide();  
                    jQuery('#loginLink').fadeOut(); 
                    location.reload(true);
                }  
            }  
            
         
        </script>  

    </f:view>
</ui:composition>

